exports.combinations = function (collection, m) {
    let n = collection.length;
    if (m >= n) {
        return collection.slice(0);
    }

    if (m <= 0) {
        return [];
    }

    let result = [];
    let tmp = [];

    let inner = function (start, choose) {
        if(choose === 0) {
            result.push(tmp.slice(0));
        } else {
            for (let i = start; i <= n - choose; i++) {
                tmp.push(collection[i]);
                inner(i + 1, choose - 1);
                tmp.pop();
            }
        }
    };

    inner(0, m);
    return result;
};

let testCombination = function () {
    console.dir(exports.combinations(['AS', '2S', '3S', '4S', '5S', '6S', '7S'], 5));
};